__author__ = 'Administrator'
from testMode.BaseTestCase import *
from testBaseOperate.BaseGetYam import *
import json
from testBaseOperate.BaseOperateElement import *
from testReport.testLog import *
from testData.Global import *
def getModeList(f):
    bs = []
    gh = getYam(f)
    for i in range(len(gh)):
        bt = BaseTestCase()
        bt.element_info = gh[i]["element_info"]
        bt.operate_type = gh[i]["operate_type"]
        bt.element_type = gh[i]["findElemtType"]
        if gh[i].get("msg", "false") != "false":
            bt.msg = gh[i]["msg"]
        bs.append(json.loads(json.dumps(bt.to_primitive())))
        # bts.btList = [bt]
    print(bs)
    return bs


# result = {"info":[]}
# result["test_success"] = 0
# result["test_sum"] = 0
# result["test_failed"] = 0
# result["test_error"] = 0
class BexceCase():
    """
    :param f: 读取用例文件位置
    :param kwargs: test_id,test_intr,test_case,isLast
    :return:
    """
    def __init__(self, result=""):
        self.result = result
        # self.result["test_module"] = test_module
        #
        # self.result["test_success"] = 0
        # self.result["test_sum"] = 0
        # self.result["test_failed"] = 0
        # self.result["test_error"] = 0
    def execCase(self, f, **kwargs):

        bc = getModeList(f)
        go = getOperateElement(driver=common.DRIVER)
        ch_check = bc[-1]
        for k in bc:
            if k["operate_type"] != None:
                go.operate_element(k["operate_type"], k["element_type"],k["element_info"], msg=k["msg"])
        logTest = myLog.getLog()
        temp = getTempCase()
        temp.test_id = kwargs["test_id"]
        temp.test_intr = kwargs["test_intr"]
        temp.test_case =kwargs["test_case"]

        if go.findElement(ch_check["element_type"], ch_check["element_info"],k["msg"]): #首页也可以指定多个检查点 配置yam文件即可
            logTest.resultOK(self.result["test_module"])
            self.result["test_success"] += 1
            common.test_success_title += 1
            temp.test_report = "成功"
        else:
            logTest.resultNG(self.result["test_module"])
            self.result["test_failed"] += 1
            common.test_failed_title += 1
            temp.test_report = "失败"
        self.result["test_sum"] += 1
        common.test_sum_title += 1
        print("---------------------------------------")
        print(json.loads(json.dumps(temp.to_primitive())))
        self.result["info"].append(json.loads(json.dumps(temp.to_primitive())))
        if kwargs["isLast"] == "1":
        # 最后case要写最下面的统计步骤
            common.RRPORT["data"].append(self.result)
# getModeList(r"D:\appium\testcase\myinfo\login.yaml")



